<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>密码修改</title>
    <link rel="stylesheet" type="text/css" href="css/adminContent.css" />
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
    <!-- 导入 Vue 3 -->
    <script src="//unpkg.com/vue@next"></script>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div class="body">
    <form name="form1" id="form1">
        <table width="100%" cellspacing="0">
            <tr><td colspan="2" style="text-align: center;color: red;" id="tip" v-html="tip"></td></tr>
            <h1 style="text-align: center">密码修改</h1>
            <tr>
                <td width="46%">账号</td>
                <td><input v-model="person.uid" disabled="disabled" name="uid"  value="user.uid"/><span ></span></td>
            </tr>
            <tr>
                <td>新密码</td>
                <td><input v-model="user.pwd"  name="uname"/><span ></span></td>
            </tr>
            <tr>
                <td>重新输入密码</td>
                <td><input v-model="user.pwd1"   /><span ></span></td>
            </tr>

            <tr>
                <td colspan="2" id="btnPanel">
                    <input type="button" value="修改" @click="doChange()"/>
                    <input type="button" value="清空" @click="doClear()"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
<script src="../js/jquery-1.8.0.min.js" type="text/javascript" charset="utf-8"></script>
<script>
    Vue.createApp({
        data(){
            return {
                user:{},
                person:{},
                tip:'&nbsp;'
            }
        },
        methods:{
            doChange() {
                if (this.user.pwd === this.user.pwd1) {
                    axios({
                        method: 'post',
                        url: '/users/changePwd',
                        params: {
                            uid: this.person.uid,
                            pwd: this.user.pwd,
                            level:1
                        }
                    }).then(res => {
                        let ret = res.data;
                        if (ret == true) {
                            this.tip = "更新成功！";
                        } else {
                            this.tip = "更新失败！";
                        }
                    });
                }else {
                    layer.msg("密码不一致")
                }
            },
            doClear() {
                this.user = {
                    uid:'',
                    uname:'',
                    uphone:'',
                    uemail:'',
                }
            }
        },
        created(){
            if (JSON.parse(localStorage.getItem("person")) != null) {
                this.person = JSON.parse(localStorage.getItem("person"))
            } else {
                layer.msg('尚未登录，请先登录!')
            }

        }
    }).mount("#form1");
</script>
</html>
